﻿using System;
using System.IO;
using SevenZip;
using SevenZip.Compression;

namespace LZMA_compression
{   
    public class LzmaTestClass
    {
        public static MemoryStream GetMemoryStreamFile(string filename,MemoryStream ms)
        {
            FileStream fs = File.Open(filename, FileMode.Open);
            byte[] bytesRead = new byte[fs.Length];
            fs.Read(bytesRead, 0, bytesRead.Length);
            ms.Write(bytesRead, 0, bytesRead.Length);

            fs.Close();
            return ms;
        }

        public static void WriteMemoryStreamToFile(MemoryStream ms, string filename)
        {
            FileStream fs = File.Open(filename, FileMode.OpenOrCreate);
            byte[] bytesRead = new byte[ms.Length];
            ms.Read(bytesRead, 0, bytesRead.Length);
            fs.Write(bytesRead, 0, bytesRead.Length);

            fs.Close();
        }

        static void Main()
        {
            LZMACoder coder = new LZMACoder();
            MemoryStream ms = new MemoryStream();

            using (ms)
            {
               MemoryStream compressedMS= coder.compress(GetMemoryStreamFile("pesho.txt", ms));
               WriteMemoryStreamToFile(compressedMS, "pesho.zip");
            }
            
        }
    }


}